<?php
/**
 *
 * @author henry
 * @version 
 */
require_once 'Zend/View/Interface.php';

/**
 * BaseUrl helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Zend_View_Helper_OutputCate {
	
	/**
	 * @var Zend_View_Interface 
	 */
	public $view;
	
	/**
	 *  
	 */
	public function outputCate($data,$catString = null) {
            if (empty ($data)) return "";
            if (!is_array($data)) throw new Exception("Phai la Array trong outputCate");
            $result = "<ul>";
            
            foreach ($data as $item){
                $check = preg_match("/".$item['id']."/i", $catString)?"checked=\"checked\"":"";
                $child = "<li><input {$check} type=\"checkbox\" value=\"".$item['id']."\"  name=\"cat[]\" />&nbsp;".$item['title'];
                $child .= $this->outputCate($item['child'],$catString);
                $child .= "</li>";
                $result .= $child;
            }                  
            $result .= "</ul>";
            return $result;
	}
	
	/**
	 * Sets the view field 
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}
}
